package com.assessment.controller;


import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.assessment.entity.ABCDNum;
import com.assessment.entity.AScoreNum;
import com.assessment.entity.Column;
import com.assessment.service.AscoreService;
import io.swagger.annotations.Api;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import static com.assessment.utils.Constant.TABLE_FAILED;
import static com.assessment.utils.Constant.TABLE_SUCCESS;
import static com.assessment.utils.ReturnMap.failedMap;
import static com.assessment.utils.ReturnMap.successMap;
import static com.baomidou.mybatisplus.core.toolkit.ObjectUtils.isEmpty;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 鑫十一
 * @since 2021-12-15
 */
@CrossOrigin
@RestController
@Api(tags={"各选项打分人数信息统计"})
@RequestMapping("/admin/abcdNum")
public class ABCDNumController {
    private final AscoreService service;

    public ABCDNumController(AscoreService service) {
        this.service = service;
    }

    // 获取分页列表
    @GetMapping("/getList")
    public Map<String,Object> getList(@RequestParam(required = false, value = "searchInfo") String item)
    {
        // 获取人数
        try {
            String pname = "";
            if (item!=null){
                JSONObject jsonObject = JSON.parseObject(item);
                if (!isEmpty(jsonObject.get("pname"))) {
                    pname = (String) jsonObject.get("pname");
                }
            }
            List<ABCDNum> list = service.getABCDNumlist(pname);
            List<Column> columns = service.getABCDColumns();
            Map<String, Object> res = new HashMap<>();
            res.put("columns",columns);
            res.put("data",list);
            return successMap(TABLE_SUCCESS,res);
        }catch (Exception e){
            e.printStackTrace();
            return failedMap(TABLE_FAILED);
        }
    }
}

